<%-- 
    Document   : lab
    Created on : 2019-2-17, 16:53:57
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    session.setAttribute("url", "../main/bussiness.jsp");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>        
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/color.css" type="text/css" />
        <link rel="stylesheet" href="../../css/demo.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript">
            //检查输入项是否存在于下拉框选项中
            function checkComboBoxValue(id) {
                var value = $(id).combobox('getValue');
                var valueField = $(id).combobox("options").valueField;
                var allData = $(id).combobox("getData");
                var result = false;
                for (var i = 0; i < allData.length; i++) {
                    if (value == allData[i][valueField]) {
                        result = true;
                        break;
                    }
                }
                return result;
            }

            $.extend($.fn.validatebox.defaults.rules, {
                selectValueRequired: {
                    validator: function(value, param) {
                        //console.info($(param[0]).find("option:contains('" + value + "')").val());
                        return checkComboBoxValue(param[0]);
                    },
                    message: '该输入项为必选项'
                }
            });
            $(document).ready(function() {
                $('#dgstudent').datagrid({
                    pagination: true,
                    pageList: [20, 50, 100],
                    pageSize: 20,
                    height: ($(window).height() - 3) + 'px'
                });
            });
            //轨迹链接
            function anchorPath(value, row) {                
                if (value != null && value != '') {                    
                    return "<a target='view_window' href='showPath.jsp?rid="
                            + value + "'>" + "√" + "</a>";  //图片链接
                } else {
                    return "<font color='red'>" + "×" + "</font>";
                }
            }
            //图片链接
            function anchorPic(value, row) {
                //var time = row.arrivalTime.subString(0,6);
                //var factoryCode=row.factoryCode;
                if (value != null && value != '') {
                    //return "<a target='view_window' href='../../photo/"+
                    //        time+"/"+factoryCode+"/'+value>"+"√"+"</a>";  //图片链接
                    return "<a target='view_window' href='../../photo/"
                            + value + "'>" + "√" + "</a>";  //图片链接
                } else {
                    return "<font color='red'>" + "×" + "</font>";
                }
            }
            function exportExcel() {                
                var options = $('#dgstudent').datagrid('getPager').data("pagination").options;
                var pageNumber = options.pageNumber;
                var pageSize = options.pageSize;  //导出excel不需要分页
                
                var params = {searchKey: $('#fuzzyWord').textbox('getValue'),
                        factoryCode: $('#factoryCode').combobox('getValue'),
                        companyCode: $('#companyCode').combobox('getValue'),
                        dateFrom: $('#ddFrom').datebox('getValue'),
                        dateTo:$('#ddTo').datebox('getValue'),
                        page:pageNumber,
                        rows:pageSize};
                var urlStr = toUrlParamString(params);
                //alert(urlStr);
                var url = '../../servlet/util/ExcelFileCreate?' + urlStr;
                //open(encodeURI(url));
                open(url);
            }
            function exportPics() {
                var options = $('#dgstudent').datagrid('getPager').data("pagination").options;
                var pageNumber = options.pageNumber;
                var pageSize = options.pageSize;  //导出图片不需要分页
                var params = {searchKey: $('#fuzzyWord').textbox('getValue'),
                        factoryCode: $('#factoryCode').combobox('getValue'),
                        companyCode: $('#companyCode').combobox('getValue'),
                        dateFrom: $('#ddFrom').datebox('getValue'),
                        dateTo:$('#ddTo').datebox('getValue'),
                        page:pageNumber,
                        rows:pageSize};
                var urlStr = toUrlParamString(params);
                var url = "../../servlet/util/DownloadAll?"+ urlStr;
                //open(encodeURI(url));
                open(url);
            }

            function toUrlParamString(param, key) {
                var paramStr = "";
                if (param instanceof String || param instanceof Number || param instanceof Boolean) {
                    paramStr += "&" + key + "=" + encodeURIComponent(param);
                } else {
                    $.each(param, function(i) {
                        var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
                        paramStr += '&' + toUrlParamString(this, k);
                    });
                }
                return paramStr.substr(1);
            };

            function doSearch() {
                $('#dgstudent').datagrid('load', {
                    searchKey: $('#fuzzyWord').textbox('getValue'),
                    factoryCode: $('#factoryCode').combobox('getValue'),
                    companyCode: $('#companyCode').combobox('getValue'),
                    dateFrom: $('#ddFrom').datebox('getValue'),
                    dateTo: $('#ddTo').datebox('getValue'),
                });
            }
            function doSearchAll() {
                $('#fuzzyWord').textbox('clear');
                $('#factoryCode').combobox('clear');
                $('#companyCode').combobox('clear');
                $('#ddFrom').datebox('clear');
                $('#ddTo').datebox('clear');
                $('#dgstudent').datagrid('load', {
                    searchKey: $('#fuzzyWord').textbox('getValue'),
                    factoryCode: $('#factoryCode').combobox('getValue'),
                    companyCode: $('#companyCode').combobox('getValue'),
                    dateFrom: $('#ddFrom').datebox('getValue'),
                    dateTo: $('#ddTo').datebox('getValue'),
                });
            }
        </script>
    </head>
    <body class="easyui-layout">        
        <table id="dgstudent" title="业务数据" class="easyui-datagrid"
               url="../../servlet/web/cargo/Load"
               toolbar="#toolbar"
               rownumbers="true" fitColumns="true" singleSelect="true">
            <thead>
                <tr>                   
                    <th field="status" hidden="true">ID</th>
                    <th field="ID" hidden="true">ID</th>
                    <th field="recordNo" width="200">编号</th>
                    <th field="arrivalTime" width="100" hidden="true">时间</th>                    
                    <th field="factoryName" width="120">客户</th>
                    <th field="plateNo" width="80">车牌号</th>
                    <th field="productName" width="80">货物</th>
                    <th field="grossWeight" width="80">毛重(吨)</th>
                    <th field="tareWeight" width="80">皮重(吨)</th>
                    <th field="minusImpurity" width="80">扣杂(吨)</th>                    
                    <th field="netWeight" width="80">净重(吨)</th>
                    <th field="frontPhoto" width="25" data-options="formatter:anchorPic">头</th>
                    <th field="sidePhoto" width="25" data-options="formatter:anchorPic">货</th>
                    <th field="licensePhoto" width="25" data-options="formatter:anchorPic">证</th>
                    <th field="paperPhoto" width="25" data-options="formatter:anchorPic">单</th>
                    <th field="tripRid" width="25" data-options="formatter:anchorPath">迹</th>
                    <th field="companyName" width="100">供应商</th>
                    <th field="siterName" width="80">驻厂员</th>
                </tr>
            </thead>
        </table>
        <div id="toolbar">            
            <select class="easyui-combobox" name="companyCode" id="companyCode" 
                    validType="selectValueRequired['#companyCode']"
                    style="width:250px"
                    data-options="valueField:'code',textField:'name',prompt:'请选择供应商',
                    url:'../../servlet/web/mycompany/Load4Combo',
                    editable:true">
                <option>请选择供应商</option>
            </select>           
            <select class="easyui-combobox" name="factoryCode" id="factoryCode" 
                    validType="selectValueRequired['#factoryCode']"
                    style="width:250px"
                    data-options="valueField:'code',textField:'name',prompt:'请选择客户',
                    url:'../../servlet/web/factory/Load4Combo',
                    editable:true">
                <option>请选择客户</option>
            </select>           
            
            <input id="ddFrom" type="text" class="easyui-datebox"  data-options="prompt:'选择查询开始日期'">
            <input id="ddTo" type="text" class="easyui-datebox"  data-options="prompt:'选择查询结束日期'">
            <input id="fuzzyWord" class="easyui-textbox" style="margin-left:20px;line-height:26px;border:1px solid #ccc" data-options="prompt:'输入查询关键字'">
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="doSearch()">查询</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-all" plain="true" onclick="doSearchAll()">清空搜索条件</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-excel" plain="true" onclick="exportExcel()">导出</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-large-picture" plain="true" onclick="exportPics()">导出图片</a>
        </div>        
    </body>
</html>
